import subprocess


def win_cmd(cmd):
    try:
        result = subprocess.run(cmd, stdout=subprocess.PIPE,shell=True)

        print("Standard Error:")
        print(result.stderr)

        Output = result.stdout
        if len(Output)<500:
            print("Standard Output:")
            print(Output)

        return Output
    except FileNotFoundError as e:
        print('res')
        print(f"Error: {e}")
        return f"Error: {e}"






# adb shell screencap -p
# win_cmd(['d:',';','cd','D:/Program Files (x86)/MuMu Player 12/shell',';','start','MuMuPlayer.exe'])
# import subprocess
#
# import cv2
# import numpy as np
#
#
# def get_screenshot():
#     process = subprocess.Popen('adb shell screencap -p', shell=True, stdout=subprocess.PIPE)
#     screenshot_methods = process.stdout.read()
#     binary_screenshot = screenshot_methods.replace(b'\r\n', b'\n')
#     img = cv2.imdecode(np.frombuffer(binary_screenshot, np.uint8), cv2.IMREAD_COLOR)
#
#
#
#     cv2.imshow('screenshot_methods', img)
#     cv2.waitKey(0)
#     cv2.destroyAllWindows()
#     cv2.imwrite('screenshot_methods.png', img)
#     print('截图已保存为screenshot.png')
#     return img
